package com.comtime.entity;

import java.util.ArrayList;

import com.bumptech.glide.Glide;
import com.comtime.smartkilimanjaro.R;
import com.comtime.utils.GlideCircleTransform;
import com.comyou.roundimageview.RoundedImageView;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class PingLunListAdapter extends BaseAdapter {

	ArrayList<PinglunInfo> pinglunInfos;
	Context context;

	public PingLunListAdapter(Context context, ArrayList<PinglunInfo> infos) {
		this.context = context;
		pinglunInfos = infos;
	}

	public void setPinglunInfos(ArrayList<PinglunInfo> infos) {
		pinglunInfos = infos;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return pinglunInfos == null ? 0 : pinglunInfos.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View view, ViewGroup arg2) {
		ViewHolder holder = null;
		if (view == null) {
			holder = new ViewHolder();
			view = LayoutInflater.from(context).inflate(
					R.layout.list_info_comment, null);
			holder.image_photo = (RoundedImageView) view
					.findViewById(R.id.image_photo);
			holder.tv_name = (TextView) view.findViewById(R.id.tv_name);
			holder.tv_time = (TextView) view.findViewById(R.id.tv_time);
			holder.tv_content = (TextView) view.findViewById(R.id.tv_content);

			view.setTag(holder);
		} else {
			holder = (ViewHolder) view.getTag();
		}
		PinglunInfo pinglunInfo = pinglunInfos.get(position);
		holder.tv_name.setText(pinglunInfo.getName());
		holder.tv_content.setText(pinglunInfo.getComment_content());
		holder.tv_time.setText(pinglunInfo.getCreate_time());
		Glide.with(context).load(pinglunInfo.getTx_img())
				.error(R.drawable.icon_portrait)
				.bitmapTransform(new GlideCircleTransform(context))
				.into(holder.image_photo);

		return view;
	}

	private class ViewHolder {
		RoundedImageView image_photo;
		TextView tv_name, tv_time, tv_content;

	}
}
